package Controller;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;

import Dao.ViewRequestDao;
import View.EmployeeView;
import View.Start;

public class EmployeeController {
	private EmployeeView view = null;
	private JFrame frame;
	private JInternalFrame iframe;
	
	public EmployeeController(){
		view = new EmployeeView();
		frame = new JFrame();
		frame.add(view);
		doAction();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Dimension screensize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		frame.setBounds(screensize.width/2-400,screensize.height/2 - 350,800,700);
		frame.setVisible(true);
//		iframe = new StartController().getFrame();
//		view.add(iframe);
	}
	
	private void doAction(){
		doSearch();
		doViewRequest();
		doRequest();
		doExit();
	}
	
	private void doSearch(){
		view.doSearch(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new SearchController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	
	private void doViewRequest(){
		view.doViewRequest(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new ViewRequestController().getFrame();
				
				view.addFrame(iframe);
			}
		});
	}
	
	private void doRequest(){
		view.doRequest(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if (iframe!= null) iframe.dispose();
				iframe = new RequestTransferEmpController().getFrame();
				view.addFrame(iframe);
			}
		});
	}
	private void doExit(){
		view.doExit(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				frame.dispose();
			}
		});
	}
}